﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace HRM.Web.master
{
    public partial class ManageJobTitles : System.Web.UI.Page
    {
        #region Pageload
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                BindGrid();
            }

        }
        #endregion

        #region GridView and Method

        private void MakeAccessible(GridView grid)
        {
            if (grid.Rows.Count > 0)
            {
                //This replaces <td> with <th> and adds the scope attribute
                grid.UseAccessibleHeader = true;
                //grid.FooterRow.TableSection = TableRowSection.TableFooter;

                //This will add the <thead> and <tbody> elements
                grid.HeaderRow.TableSection = TableRowSection.TableHeader;

                //This adds the <tfoot> element. Remove if you don't have a footer row
                //grid.FooterRow.TableSection = TableRowSection.TableFooter;
            }
        }

        public void BindGrid()
        {
            BLL.Login objRole = new BLL.Login();
            DataTable dt = objRole.GetAllLogins();
            grdJobTitles.DataSource = dt;
            grdJobTitles.DataBind();
            MakeAccessible(grdJobTitles);
        }

        protected void grdJobTitles_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int intJobTitleID = Convert.ToInt32(e.CommandArgument);
            GridViewRow row = (GridViewRow)(((Button)e.CommandSource).NamingContainer);

            if (e.CommandName == "EditCommand")
            {
                Response.Redirect("AddJobTitles.aspx?JobTitleID=" + intJobTitleID);

            }
            else if (e.CommandName == "EditCommand")
            {
                BLL.Login BLL_objLogin = new BLL.Login();

                //get the status of deleted item
                int IsDeleted = BLL_objLogin.Delete(intJobTitleID);


                if (IsDeleted == 0)
                {
                    divAlertDelete.Visible = true;
                    ltrMessageDelete.Text = "This record has been deleted successfully.";
                    BindGrid();
                }
                else
                {
                    //show data exist.
                    divAlertDelete.Visible = true;
                    ltrMessageDelete.Text = "Cannot delte this record. Data exist under this record.";

                }
            }
            else
            {
            }

        }

        #endregion
    }
}